package lxs.swift.verify.getters;

import lxs.swift.verify.Asserts;
import lxs.swift.verify.Verifies;
import org.jetbrains.annotations.NotNull;

import java.util.function.Predicate;

public interface CompareGet<T, V extends Comparable<V>> extends Get<T, V> {
    default Predicate<T> gt(@NotNull V v) {
        return t -> {
            V val = this.get(t);
            if (val == null) return false;
            return val.compareTo(v) > 0;
        };
    }

    default Predicate<T> gte(@NotNull V v) {
        return t -> {
            V val = this.get(t);
            if (val == null) return false;
            return val.compareTo(v) >= 0;
        };
    }

    default Predicate<T> lt(V v) {
        return t -> {
            V val = this.get(t);
            if (val == null) return false;
            return val.compareTo(v) < 0;
        };
    }

    default Predicate<T> lte(V v) {
        return t -> {
            V val = this.get(t);
            if (val == null) return false;
            return val.compareTo(v) <= 0;
        };
    }

    default Predicate<T> between(V left, V right) {
        return t -> {
            V v = this.get(t);
            return Verifies.between(v, left, right);
        };
    }
}
